﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WebApi0002.Domain.Entity;

namespace WebApi0002.Domain
{
    public class DbInitializeHelper
    {
        public static void Initilizer()
        {
            using(var db=new Admin4000DbContext())
            {
                var dbExist=db.Database.EnsureCreated();
                var tempBrand = db.Brands.Any();


                if (!tempBrand)
                {
                    var brand = new Brand
                    {
                        BrandName = "Apple",
                        Description = "美国品牌"
                    };
                    db.Brands.Add(brand);
                    db.SaveChanges();
                    db.Products.AddRange(new Product[]
                    {
                    new Product
                    {
                        ProductName="Iphone X 黑色",
                        ShortDesc="这是一个简单的描述",
                        FullDesc="这是一个详情",
                        BrandId=brand.Id
                    },

                    new Product
                    {
                        ProductName="Iphone X 粉色",
                        ShortDesc="这是一个超级详细的描述",
                        FullDesc="这是一个包包",
                        BrandId=brand.Id
                    }
                    });

                    db.SaveChanges();
                }

                
            }
        }
    }
}
